package components.game
{
	import SEApp.se_util;
	
	import UIFree.ObjectEvent;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import classes.clt_events;
	import components.tools.photos.clt_userAvatar;
	
	import data.clt_data;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;

	public class clt_collageItem extends clt_userAvatar {
		private var _stiker: clt_stiker;
		public function clt_collageItem(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, userData:Object=null, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, userData, styleClass);
			addEvent(MouseEvent.CLICK, doClick);
			if (userData && userData.name) image.hint = userData.name;
			
			addEvent(Event.COMPLETE, doImageLoad, image.source.contentLoaderInfo);
		}
		
		protected function doImageLoad(e: Event): void {
			if (This.data.stiker) createStiker();
		}
		
		protected function createStiker(): void {
			_stiker = new clt_stiker(this, 0, 0, 'stiker');
			_stiker.setID(This.data.stiker, 40, function(): void {
				_stiker.x = 65;
				_stiker.y = 75 - _stiker.height;
			});
		}
		
		public function doView(): void {
			clt.workspace.dispatchEvent(new ObjectEvent(clt_events.SHOWGAMEITEM, this));
		}
		
		override protected function get imageURL(): String {
			return (_dataItem)?(clt_servers.GAMEPREVIEW_URL + _dataItem.id + clt_data.JPGEXT):null;
		}
		
		override protected function get text(): String {
			return (_dataItem)?(Utils.ll(se_util.userName(_dataItem), 12) + '\nрейтинг: ' + _dataItem.rate):null;
		}
		
		protected function doClick(e: MouseEvent): void {
			doView();
		}		
	}
}